package com.abocode.aichat.server.worker;

import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.Module;
import com.abocode.aichat.server.stanza.StanzaHandlerContext;
import io.netty.channel.Channel;

/**
 * Created by franky-14.
 */
public abstract class StanzaWorker implements Worker<Channel> {

    protected StanzaHandlerContext stanzaHandlerContext = new StanzaHandlerContext();

    protected ServerRuntimeContext serverRuntimeContext;

    @Override
    public void addModule(Module module) {
        if (serverRuntimeContext == null) {
            throw new NullPointerException("serverRuntimeContext is null");
        }
        module.setRuntimeContext(serverRuntimeContext);
        stanzaHandlerContext.register(module);
    }


    @Override
    public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
        if (serverRuntimeContext == null) {
            throw new NullPointerException("serverRuntimeContext is null");
        }
        this.serverRuntimeContext = serverRuntimeContext;
    }

    @Override
    public ServerRuntimeContext getServerRuntimeContext() {
        return serverRuntimeContext;
    }
}
